import { Column, Entity, ManyToMany } from 'typeorm';
import { BaseEntity } from '@src/common/entity/base.entity';
import { Role } from '@src/role/entity/role.entity';

@Entity({ name: 'permissions' })
export class Permission extends BaseEntity {
  @Column({ type: 'varchar', length: 100, comment: '资源名称，如 user' })
  resource: string;

  @Column({ type: 'varchar', length: 50, comment: '操作类型' })
  action: string;

  @Column({
    type: 'varchar',
    length: 200,
    unique: true,
    comment: '权限码，如 user:create',
  })
  code: string;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '描述' })
  description?: string;

  @ManyToMany(() => Role, (role) => role.permissions, { onDelete: 'CASCADE' })
  roles: Role[];
}
